package com.hnevc.shuqiangjian;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

    private Button turnOnBtn;
    private Button turnOffBtn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    initView();
    initData();
    initEvent();
    }
    private void initView() {
        turnOnBtn = findViewById(R.id.turnOn_btn);
        turnOffBtn = findViewById(R.id.turnOff_btn);
    }

    private void initData() {

    }
    private void initEvent() {
    turnOnBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //通过意图启动Service
            Intent intent = new Intent(MainActivity.this,MyService.class);
            startService(intent);
        }
    });
    turnOffBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(MainActivity.this,MyService.class);
            stopService(intent);
        }
    });
    }

}